package com.yumis.service.modules.upload.controller;

import com.yumis.service.common.enums.HttpState;
import com.yumis.service.common.vo.Response;
import com.yumis.service.modules.upload.service.UploadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@RequestMapping("upload")
public class UploadController {

    @Autowired
    private UploadService uploadService;

    @PostMapping("file")
    public Response uploadFile(@RequestParam("dir") String fileDir, @RequestParam("file") MultipartFile file) {
        return Response.buildResponse(HttpState.OK, uploadService.uploadFile(fileDir, file));
    }

    @PostMapping("delete")
    public ResponseEntity<Response> deleteImage(@RequestParam("url") String url) {
        uploadService.deleteImage(url);
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK));
    }

}
